/* sfglrp.p - GENERAL LEDGER REPORT FROM TEMP-TABLE TT_GLTW_WKFL        */
/* Copyright 1986-2011 QAD Inc., Santa Barbara, CA, USA.                      */
/* All rights reserved worldwide.  This is an unpublished work.         */
/* $Id:: sfglrp.p 2366 2010-11-10 01:47:19Z zzh                            $: */
/*V8:ConvertMode=Report                                                 */
/* Revision: 1.2.1.1  BY: Vandna Rohira      DATE: 07/10/01 ECO: *M1DM* */
/* Revision: 1.2.1.3  BY: Paul Donnelly (SB) DATE: 06/28/03 ECO: *Q00L* */
/* Revision: 1.2.1.5  BY: Katie Hilbert    DATE: 04/24/08 ECO: *R0RX*     */
/* $Revision: 1.2.1.6 $    BY: Huaping Luo        DATE: 03/08/10  ECO: *R22T*   */
/*-Revision end---------------------------------------------------------------*/
/************************************************************************/

/******************************************************************************/
/* All patch markers and commented out code have been removed from the source */
/* code below. For all future modifications to this file, any code which is   */
/* no longer required should be deleted and no in-line patch markers should   */
/* be added.  The ECO marker should only be included in the Revision History. */
/******************************************************************************/

/* THIS PROGRAM IS SIMILAR TO gpglrp.p AND CHANGES DONE IN gpglrp.p  */
/* MAY ALSO BE NEEDED IN sfglrp.p                                    */

{us/bbi/mfdeclre.i}
/* EXTERNAL LABEL INCLUDE */
{us/bbi/gplabel.i}

define variable nbr_entities as integer                         no-undo.
define variable dr_amt       like glt_amt label "Debit Amount"  no-undo.
define variable cr_amt       like glt_amt label "Credit Amount" no-undo.
define variable tmp_fmt      as   character                     no-undo.

/* TEMP-TABLE DEFINITION of tt_gltw_wkfl */
{us/sf/sfgltwdf.i}

for first gl_ctrl
   fields( gl_domain gl_rnd_mthd)
   where gl_ctrl.gl_domain = global_domain no-lock:
end. /* FOR FIRST gl_ctrl */


/* get periodic costing control file */
find first pcsc_ctrl no-lock where pcsc_domain = global_domain
   no-error.

form
   header
   getTermLabel("GENERAL_LEDGER_DETAIL",34) + " " format "x(35)"
   skip (1)
with frame frm_gltw_hdr width 132 page-top.

view frame frm_gltw_hdr.

nbr_entities = 0.

form
   tt_gltw_entity
   tt_gltw_acct
   tt_gltw_sub
   tt_gltw_cc
   tt_gltw_project
   tt_gltw_date column-label "Date!Eff Date"
   tt_gltw_desc format "x(28)"
   dr_amt
   cr_amt
with frame frm_gltw_det width 132 down no-box.

/* SET EXTERNAL LABELS */
setFrameLabels(frame frm_gltw_det:handle).

do with frame frm_gltw_det:

   tmp_fmt = dr_amt:format.
   {us/bbi/gprun.i ""gpcurfmt.p"" "(input-output tmp_fmt,
                             input gl_rnd_mthd)"}
   dr_amt:format = tmp_fmt.

   tmp_fmt = cr_amt:format.
   {us/bbi/gprun.i ""gpcurfmt.p"" "(input-output tmp_fmt,
                             input gl_rnd_mthd)"}
   cr_amt:format = tmp_fmt.

   for each tt_gltw_wkfl exclusive-lock
         break by tt_gltw_entity
         by tt_gltw_acct
         by tt_gltw_sub
         by tt_gltw_cc
         by tt_gltw_project
         by tt_gltw_effdate
      with frame frm_gltw_det width 132 no-box:

      assign
         cr_amt = 0
         dr_amt = 0.

      if tt_gltw_amt < 0
      then
         cr_amt = - tt_gltw_amt.
      else
         dr_amt = tt_gltw_amt.

      accumulate (dr_amt) (total by tt_gltw_entity by tt_gltw_acct).
      accumulate (cr_amt) (total by tt_gltw_entity by tt_gltw_acct).

      if first-of (tt_gltw_entity)
      then
         display tt_gltw_entity.

      if first-of (tt_gltw_acct)
      then
         display tt_gltw_acct.

      if first-of (tt_gltw_sub)
      then
         display tt_gltw_sub.

      if first-of (tt_gltw_cc)
      then
         display tt_gltw_cc.

      display
         tt_gltw_project
         tt_gltw_date
         tt_gltw_desc.

      if dr_amt <> 0
      then
         display dr_amt.

      if cr_amt <> 0
      then
         display cr_amt.

      down 1.

      display
         tt_gltw_effdate @ tt_gltw_date.
      down 1.

      {us/mf/mfrpchk.i}

      if last-of(tt_gltw_acct)
      then do:
         underline dr_amt cr_amt.
         display
         getTermLabel("ACCOUNT_TOTAL", 8) + ": "
           when available pcsc_ctrl and pcsc_ctrl.pcsc_enable = yes
          @ tt_gltw_desc
            accum total by tt_gltw_acct dr_amt @ dr_amt
            accum total by tt_gltw_acct cr_amt @ cr_amt.
         down 1.
      end. /* IF LAST-OF(tt_gltw_acct) */

      if last-of(tt_gltw_entity)
      then do:
         nbr_entities = nbr_entities + 1.
         underline dr_amt cr_amt.
         display
            getTermLabel("ENTITY_TOTAL", 8) + ": "
            when available pcsc_ctrl and pcsc_ctrl.pcsc_enable = yes
               @ tt_gltw_desc
            accum total by tt_gltw_entity dr_amt @ dr_amt
            accum total by tt_gltw_entity cr_amt @ cr_amt.
         down 1.
      end. /* IF LAST-OF(tt_gltw_entity) */

      if  last(tt_gltw_entity)
         and nbr_entities > 1
      then do:
         underline dr_amt cr_amt.
         display
            accum total dr_amt @ dr_amt
            accum total cr_amt @ cr_amt.
      end. /* IF LAST(tt_gltw_entity) AND nbr_entries > 1 */

      delete tt_gltw_wkfl.

   end. /* FOR EACH tt_gltw_wkfl */

end. /* DO WITH FRAME frm_gltw_det */
